import axios from "axios"
import axiosRetry from "axios-retry"

const instance = axios.create({
    baseURL: '/api',
    timeout: 20000
})
axiosRetry(instance, {
    retries: 3,
    retryDelay: (retryCount) => {
        return retryCount * 1000
    }
})

//请求拦截器
instance.interceptors.request.use((config) => {

    const access = localStorage.getItem('access')
    config.headers.Authorization = 'Bearer' + access

    return config
}, (error) => {
    return Promise.reject(error)
})

//相应拦截器
instance.interceptors.response.use((response) => {
    return response
})

const postWay = (url, data) => {
    return instance.post(url, data)
}
const getWay = (url) => {
    return instance.get(url)
}
const deleteWay = (url, data) => {
    return instance.delete(url, data)
}
const putWay = (url, data) => {
    return instance.put(url, data)
}
export default { postWay, getWay, deleteWay, putWay }



